class Task19:
    def run(self, pattern, text):
        return self.match(pattern, 0, text, 0)

    def match(self, pattern, pattern_index, text, text_index):
        if pattern_index == len(pattern) and text_index == len(text):
            return True
        elif pattern_index == len(pattern) or text_index == len(text):
            return False
        else:
            if pattern[pattern_index] == '.':
                return self.match(pattern, pattern_index + 1, text, text_index + 1)
            elif pattern[pattern_index] == '*':
                if pattern_index - 1 < 0 or pattern[pattern_index - 1] == '*':
                    raise ValueError('invalid pattern, "*" must follow plain character or "."')
                if pattern[pattern_index - 1] == '.' or pattern[pattern_index - 1] == text[text_index]:
                    return self.match(pattern, pattern_index, text, text_index + 1) \
                        or self.match(pattern, pattern_index + 1, text, text_index)
                else:
                    return self.match(pattern, pattern_index + 1, text, text_index)
            else:
                if pattern[pattern_index] == text[text_index]:
                    return self.match(pattern, pattern_index + 1, text, text_index + 1)
                else:
                    return False
